<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link type="text/css" rel="stylesheet" href="../css/app.css"/>
    <link type="text/css" rel="stylesheet" href="../css/loginMobile.css"/>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../datepicker/jquery-ui.min.js"></script>
    <script type="text/javascript" src="/pc/js/all.js"></script>
</head>
<body id="Ibody">
<!--
	制作：陈道祥
	页面：产品种类页面
	更新：九哥
-->





<!-----------公司产品种类页面---------->
<div class="stepTwo" id="IstepTenFactoryCompanyDevice">
    <div class="companyHeadPanel">
        <div class="companyHeadOne">公司产品种类</div>
    </div>
    <div class="companyInfoSpace"></div>
    <div class="blankSpace"></div>
    <div class="modelPanel">
        <div class="goodsPanel">
            <div class="deviceInner proType"
                 style="font-size:10px;color:#999999;">
                类别、产品名称是自定义，男装、女装、童装是选择0/1
            </div>
        </div>
        <div class="goodsPanel">
            <div class="deviceInner proType">类别</div>
            <div class="deviceInner proType" >产品名称</div>
            <div class="deviceInner proType">男装</div>
            <div class="deviceInner proType">女装</div>
            <div class="deviceOuter proType">童装</div>
        </div>
        <span id="proTypeSpan"></span>
        <div class="goodsPanel">
            <div class="goodsItemThreeLast"
                 style="color:#0088cc;cursor:pointer;"
                 onclick="setProTypeAdd()"
            >确定</div>
        </div>
    </div>
    <div class="companyInfoSpace"></div>
    <div class="companyRemark">备注：方便你的客户找到你、招聘的员工找到你、了解你、信任你，图片尽量上传完善。让客户多了解自己，容易接单成功。细节决定成败，图片清晰。</div>
    <div class="nextStepDiv">
        <!--<span class="prevStep" id="comProTypePre">上一步</span>-->
        <!--<span class="nextStep" id="comProTypeNext">下一步</span>-->
        <span class="prevStep" onclick="history.go(-1)">返回</span>
        <span class="nextStep" onclick="setSave()">保存</span>
    </div>
</div>
<input type="hidden" id="index" value="0">
<!-----------公司产品种类页面---------->





<!-----------提示信息---------->
<div id="errMsg"></div>
<!-----------提示信息---------->
</body>
<script type="text/javascript" src="../js/loginCom.js"></script>
<script>
    (function(){
        getProTypes();
    })();
    /**
     * 种类，获取
     * */
    function getProTypes() {
        var userInfo = cacheGet('userInfo'); //获取用户信息
        if (userInfo == 'undefined' || userInfo.token == 'undefined') {
            getErrMsg('没有登录！');
            return;
        }
        var data = {
            app_access: app_access,
            token: userInfo.token,
            type: userInfo.type,
            cate: userInfo.cate
        };
        $.ajax({
            type: 'post',
            url: getDomain() + 'com-pro-type-list',
            data: data,
            success: function (res) {
                //console.log(res); return;
                var h = '';
                h += '<div class="goodsPanel">';
                h +=    '<div class="deviceInner proType">';
                h +=        '<input type="text" class="regCodeCenter" id="cate" placeholder="输入" value=""/>';
                h +=    '</div>';
                h +=    '<div class="deviceInner proType">';
                h +=        '<input type="text" class="regCodeCenter" id="name" placeholder="输入" value=""/>';
                h +=    '</div>';
//                h +=    '<div class="deviceInner proType">';
//                h +=        '<input type="text" class="regCodeCenter" id="male" placeholder="输入" value=""/>';
//                h +=    '</div>';
//                h +=    '<div class="deviceInner proType">';
//                h +=        '<input type="text" class="regCodeCenter" id="female" placeholder="输入" value=""/>';
//                h +=    '</div>';
//                h +=    '<div class="deviceOuter proType">';
//                h +=        '<input type="text" class="regCodeCenter" id="child" placeholder="输入" value=""/>';
//                h +=    '</div>';
                h +=    '<div class="deviceInner proType">';
                h +=        '<input type="text" class="regCodeCenter" id="male" placeholder="输入"/>';
                h +=    '</div>';
                h +=    '<div class="deviceInner proType">';
                h +=        '<input type="text" class="regCodeCenter" id="female" placeholder="输入"/>';
                h +=    '</div>';
                h +=    '<div class="deviceOuter proType">';
                h +=        '<input type="text" class="regCodeCenter" id="child" placeholder="输入"/>';
                h +=    '</div>';
                h += '</div>';
                if (res.code != 0) {
                    $('#proTypeSpan').append(h);
                    console.log(res); return;
                }
                console.log(res.data);
                var i, h2 = '', data = res.data;
                $('#index')[0].value = data.length;
                for (i=0;i<data.length;i++) {
                    h2 += '<div class="goodsPanel">';
                    h2 +=    '<div class="deviceInner proType">';
                    h2 +=        '<input type="text" class="regCodeCenter" id="cate'+i+'" value="'+data[i].cate+'"/>';
                    h2 +=    '</div>';
                    h2 +=    '<div class="deviceInner proType">';
                    h2 +=        '<input type="text" class="regCodeCenter" id="name'+i+'" value="'+data[i].name+'"/>';
                    h2 +=    '</div>';
//                    h2 +=    '<div class="deviceInner proType">';
//                    h2 +=        '<input type="text" class="regCodeCenter" value="'+data[i].male+'"/>';
//                    h2 +=    '</div>';
//                    h2 +=    '<div class="deviceInner proType">';
//                    h2 +=        '<input type="text" class="regCodeCenter" value="'+data[i].female+'"/>';
//                    h2 +=    '</div>';
//                    h2 +=    '<div class="deviceOuter proType">';
//                    h2 +=        '<input type="text" class="regCodeCenter" value="'+data[i].child+'"/>';
//                    h2 +=    '</div>';
                    h2 +=    '<div class="deviceInner proType">';
                    h2 +=        '<input type="text" class="regCodeCenter" id="male'+i+'" value="'+data[i].male+'"/>';
                    h2 +=    '</div>';
                    h2 +=    '<div class="deviceInner proType">';
                    h2 +=        '<input type="text" class="regCodeCenter" id="female'+i+'" value="'+data[i].female+'"/>';
                    h2 +=    '</div>';
                    h2 +=    '<div class="deviceOuter proType">';
                    h2 +=        '<input type="text" class="regCodeCenter" id="child'+i+'" value="'+data[i].child+'"/>';
                    h2 +=    '</div>';
//                    h2 +=    '<div class="deviceOuter proType" style="color:#888888;border:1px solid #E0E0E0;background:#F0F0F0;">';
//                    h2 +=    '点选</div>';
//                    h2 +=    '<div class="deviceOuter proType" style="border:1px solid #E0E0E0;background:#F0F0F0;">';
//                    h2 +=    '</div>';
//                    h2 +=    '<div class="deviceOuter proType" style="border:1px solid #E0E0E0;background:#F0F0F0;">';
//                    h2 +=    '</div>';
                    h2 += '</div>';
                }
                $('#proTypeSpan').html(h2);
                $('#proTypeSpan').append(h);
            },
            error: function () {
                console.log('操作失败！'); return;
            }
        });
    }
    /**
     * 设置保存
     * */
    function setSave(){
//        window.location.href = '/h5/login/comList.html';
        var userInfo = cacheGet('userInfo'); //获取用户信息
        if (userInfo == 'undefined' || userInfo.token == 'undefined') {
            getErrMsg('没有登录！');
            return;
        }
        var index = $('#index').val();
        if (index==0) {
            console.log(index);
            getErrMsg('没有数据！');
            return
        }
        var i, cate, name, male, female, child,
            cateArr = new Array(), nameArr = new Array(),
            maleArr = new Array(), femaleArr = new Array(),
            childArr = new Array();
        for (i=0;i<index;i++) {
            cate = $('#cate'+i).val();
            name = $('#name'+i).val();
            male = $('#male'+i).val();
            female = $('#female'+i).val();
            child = $('#child'+i).val();
            cateArr[i] = cate;
            nameArr[i] = name;
            maleArr[i] = male;
            femaleArr[i] = female;
            childArr[i] = child;
            if (!/^[0-9]*$/.test(male)) {
                getErrMsg('第'+i+'行男装输入格式错误！');
                console.log('第'+i+'行男装输入格式错误！');
                return
            }
            if (!/^[0-9]*$/.test(female)) {
                getErrMsg('第'+i+'行女装输入格式错误！');
                console.log('第'+i+'行女装输入格式错误！');
                return
            }
            if (!/^[0-9]*$/.test(child)) {
                getErrMsg('第'+i+'行童装输入格式错误！');
                console.log('第'+i+'行童装输入格式错误！');
                return
            }
        }
//        console.log(cateArr,nameArr,maleArr,femaleArr,childArr); return
        var formData = {
            app_access: app_access,
            token: userInfo.token,
            type: userInfo.type,
            cate: userInfo.cate,
            index:index,
            cates:cateArr,
            names:nameArr,
            males:maleArr,
            females:femaleArr,
            childs:childArr
        };
        $.ajax({
            type: 'post',
            url: getDomain() + 'com-pro-type-set2',
            data: formData,
            success: function (res) {
                //console.log(res); return;
                if (res.code!=0) {
                    getErrMsg(res.msg);
                    console.log(res);
                    return
                }
                getErrMsg('操作成功！');
                setTimeout(function(){
                    window.location.href = '/h5/login/comList.html';
                }, 1000*2);
            },
            error:function(){
                console.log('操作失败！');
            }
        });
    }
    /**
     * 地址前缀
     * */
    function getDomain(){
        return '/api/member/company/';
    }
</script>
</html>